{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "79fee780-5245-4182-9e5c-8660c9c6b58f",
   "metadata": {},
   "outputs": [],
   "source": [
    "maxlen = 128\n",
    "batchz_size = 32\n",
    "config_path = \"/bert/chinese_roberta_wwm_ext_L-12_H-768_A-12/bert_config.json\"\n",
    "dict_path = \"/bert/chinese_roberta_wwm_ext_L-12_H-768_A-12/vocab.txt\"\n",
    "checkpoint_path = \"/bert/chinese_roberta_wwm_ext_L-12_H-768_A-12/bert_model.ckpt\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a2e18fe2-cc33-422a-bf16-fdd90e1889a3",
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_data(filename):\n",
    "    D = []\n",
    "    with open(filename, encoding='utf-8', mode=\"r\") as f:\n",
    "        for l in f:\n",
    "            l = l.strip().strip(\"\\n\").strip(\"\\u200b\").strip().strip(\"\\u200b\").split(\",\")\n",
    "            text = l[2]\n",
    "            label = l[1]\n",
    "            D.append((text, int(label)))\n",
    "    return D"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "faef2aa7-3fa2-4529-b234-1197fbf81ac0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('阿拉蕾摔倒了，穿的太厚了起不来，董力把她抱了起来！{%#阿拉蕾#%} {%围观明星大宝贝的秒拍视频%}', 0),\n",
       " ('我不知道明天会是什么样子，一点儿也不期盼，但我也不会逃避，我会成长并且自治愈，我超厉害的[加油][加油][并不简单][二哈]', 1),\n",
       " ('生日快乐送给纹上小猪佩奇的社会尘[小黄人剪刀手]', 1),\n",
       " ('【27】速溶汤30包，包括：菠菜蛋花、西红柿蛋花、鲜蔬芙蓉汤、紫菜蛋花汤、小白菜蛋花汤共5种口味，冲泡即食，据说跟肯.德.基的一个味，但比肯.德.基便宜很多哦[喵喵]',\n",
       "  1),\n",
       " ('上班不是因为工作累，更是心累[悲伤]哎～ 复杂的人心 简单点不好吗？{%#hi五月#%}{%#遇见春光#%}{%#小猪嘟嘟#%}', 0)]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#加载数据集\n",
    "train_data = load_data(\"datasets/sentiment/train.txt\")\n",
    "valid_data = load_data(\"datasets/sentiment/test.txt\")\n",
    "test_data = load_data(\"datasets/sentiment/test.txt\")\n",
    "test_data[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ae70e43e-7b4e-4992-bc02-872d57cdd4bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 模拟 标注和非标注数据\n",
    "train_frac = 0.01 #标注比例\n",
    "num_labeled = int(len(train_data) * train_frac) #num_labeled: 100\n",
    "unlabeled_data = [(t, 2) for t, l in train_data[num_labeled:]]\n",
    "train_data = train_data[:num_labeled]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.19"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
